package me.xue.communityhealth.service;

import me.xue.communityhealth.exception.ObjectNotFoundException;
import me.xue.communityhealth.model.DrugType;
import me.xue.communityhealth.repo.DrugTypeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DrugTypeService implements BaseService<DrugType, Integer> {

    private final DrugTypeRepository repository;

    @Autowired
    public DrugTypeService(DrugTypeRepository repository) {
        this.repository = repository;
    }

    @Override
    public int save(DrugType drugType) {
        return repository.save(drugType);
    }

    @Override
    public int update(DrugType drugType) {
        return repository.update(drugType);
    }

    @Override
    public int delete(Integer which) {
        return repository.delete(which);
    }

    public DrugType findOne(Integer id) {
        DrugType drugType = repository.findOne(id);
        if (drugType == null) {
            throw new ObjectNotFoundException();
        }
        return drugType;
    }

    @Override
    public List<DrugType> findAll() {
        return repository.findAll();
    }
}
